﻿Namespace Util
    Public Class ConUtil

        Private _con As String = ""
        Private _user As String = ""
        Public ReadOnly Property User() As String
            Get
                Return _user
            End Get
        End Property

        Private _pwd As String = ""
        Public ReadOnly Property Pwd() As String
            Get
                Return _pwd
            End Get
        End Property

        Private _database As String = ""
        Public ReadOnly Property DataBase() As String
            Get
                Return _database
            End Get
        End Property

        Private _datasource As String = ""
        Public ReadOnly Property DataSource() As String
            Get
                Return _datasource
            End Get
        End Property

        Public Sub New(ByVal con As String)
            If con.Trim <> "" Then
                Dim cons() As String = con.Split(New String() {";"}, StringSplitOptions.RemoveEmptyEntries)
                If cons.Length > 0 Then

                    For Each item As String In cons
                        Dim keyValue() As String = item.Split(New String() {"="}, StringSplitOptions.RemoveEmptyEntries)
                        If keyValue.Length = 2 Then
                            Select Case keyValue(0).ToLower.Trim
                                Case "data source"
                                    _datasource = keyValue(1).Trim
                                Case "initial catalog"
                                    _database = keyValue(1).Trim
                                Case "user id"
                                    _user = keyValue(1).Trim
                                Case "password"
                                    _pwd = keyValue(1).Trim
                                Case "Persist Security Info"
                                    _database = keyValue(1).Trim
                            End Select
                        End If

                    Next
                End If
            End If
        End Sub
    End Class
End Namespace


